package com.njupt.Array;

/**
 * @Author: wujiaming
 * @CreateTime: 2025/2/24 15:14
 * @Description: 48. 旋转图像
 * @Version: 1.0
 */


public class Rotate_48 {
    public void rotate(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[][] rotate_cache = new int[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                rotate_cache[j][n-1-i] = matrix[i][j];
            }
        }

//        print(rotate_cache);
//        System.out.println();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                matrix[i][j] = rotate_cache[i][j];
            }
        }
//        print(matrix);
    }

    public void print(int[][] nums){
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums[i].length -1; j++) {
                System.out.print(nums[i][j] + " ");
            }
            System.out.println(nums[i][nums[i].length -1]);
        }
    }

    public static void main(String[] args) {
        int[][] matrix = {{1,2,3},{4,5,6},{7,8,9}};
        Rotate_48 test = new Rotate_48();
        test.rotate(matrix);
    }

}
